//
//  PreTransactionPageStore.swift
//  Share
//
//  Created by admin on 2020/12/7.
//  Copyright © 2020 MBA. All rights reserved.
//

import Foundation

class PreTransactionPageStore: ObservableObject {
    
    @Published var instores: [PreTransactionModen] = []
    @Published var outstores: [PreTransactionModen] = []
    @Published var loading = false
    @Published var alertData:AlertData?
  

    /**
     获取列表
     */
    func update() {
        instores.removeAll()
        outstores.removeAll()
        Share.db_shares { (error, results) in
            
            self.loading = false
            if((error) != nil){
                self.alertData = AlertData( title: "错误", message: error?.description ?? "未知")
            }else{
                self.fitteInstores(shares: results ?? [Share]())
                self.fitteOutstores(shares: results ?? [Share]())
            }
        }
        
        
    }
    
    func fitteInstores(shares:[Share]) {
        
        for share in shares {
            instores.append(contentsOf: share.fitteInstores())
        }
    }
    
    func fitteOutstores(shares:[Share]) {
        
        for share in shares {
            outstores.append(contentsOf: share.fitteOutstores())
        }
    }
}
